﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using ControleRepresentante.Logic;
using ControleRepresentante.Logic.Models;
using ControleRepresentante.Logic.Repositories;
using ControleRepresentante.Logic.Repositories.SearchExtensions;
using WebSite.ViewModels.ViewModelExtensions.DetailsViewModelExtensions;
using WebSite.ViewModels.ViewModelExtensions.EditViewModelExtensions;
using WebSite.ViewModels.ViewModelExtensions.IndexViewModelExtensions;

namespace WebSite.Controllers.ControllerExtensions
{
    public class FabricaControllerTriviumExtension : ControllerExtensionBase<Fabrica>
    {
        protected override IIndexViewModelExtension DoGetIndexViewModelExtension(FormCollection formCollection, IRepository repository)
        {
            return new FabricaTriviumIndexViewModel();
        }

        public override IEditViewModelExtension EditViewModelExtension
        {
            get { return new FabricaTriviumEditViewModel(); }
        }

        public override IDetailsViewModelExtension DetailsViewModelExtension
        {
            get { return new FabricaTriviumDetailsViewModel(); }
        }

        public override ISearchExtension GetSearchExtension(FormCollection formCollection)
        {
            return null;
        }

        public override void RegisterIndexColumns(IIndexColumnsProvider indexColumnsProvider)
        {
            indexColumnsProvider.RegisterColumn("Trivium", FabricaTriviumIndexColumns.IsTrivium);
        }

        protected override Dictionary<string, string> TryUpdateModel(Fabrica model, FormCollection formCollection)
        {
            bool isTrivium = formCollection["isTrivium"].ToLower() != "false";

            model.FabricaTrivium.IsTrivium = isTrivium;

            return new Dictionary<string, string>();
        }

        protected override Area Area { get { return Area.Fabricas; } }

        protected override void SetModel(Fabrica model)
        {
            if (model.FabricaTrivium == null)
            {
                model.SetFabricaTrivium();
            }
        }

        protected override bool CanHandle(Representante representante)
        {
            return representante.UseTrivium;
        }
    }
}